package com.vogtec.fota.entity.mqtt;

import com.vogtec.fota.mqtt.BikeWireFormatError;
import lombok.Data;

import java.io.UnsupportedEncodingException;

/**
 * Created by TieYan on 2017/3/3.
 */
@Data
public class BikeFotaAck extends BikeWireUp {
    private String bikeNum;

    @Override
    public void decode(byte[] content) throws BikeWireFormatError, UnsupportedEncodingException {
        if(content.length != 8){
            throw new BikeWireFormatError("length not match");
        }
        int index = 0;
        bikeNum = Util.byteArray2String(content, index, 8);
    }

    public static void main(String[] args) throws BikeWireFormatError, UnsupportedEncodingException {
        BikeFotaAck smsAck = new BikeFotaAck();

        byte[] bikeNum = Util.string2AsciiArray("12345678");
        byte token = 11;
        byte[] content = Util.add(bikeNum, token);

        for(byte b : content){
            System.out.println(b);
        }

        smsAck.decode(content);
        System.out.println(smsAck.bikeNum);
    }
}
